package com.example.dataservice.mapper;


import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.example.api.model.BidInfo;
import org.example.api.pojo.BidProductInfo;

import java.math.BigDecimal;
import java.util.List;

public interface BidInfoMapper {


    @Select("""
            select * 
            from b_bid_info
            where prod_id = #{productId}
            and bid_status = 1
            order by id
            """)
    /*根据产品id查新投资记录*/
    List<BidInfo> selectByProductId(Integer productId);

    @Select("""
            select
                bid.id,
                concat(substring(user.phone from 1 for 3),'******',substring(user.phone from 10 for 2)) as phone,
                bid.bid_money as money,
                DATE_FORMAT(bid.bid_time,'%Y-%m-%d %H:%i:%s') as time
            from
                b_bid_info bid
            join
                u_user user
            on
                bid.uid = user.id
            where
                bid.prod_id = #{productId}
            order by time desc
            limit #{offset}, #{pageSize}
            """)
    @ResultType(BidProductInfo.class)
    /* 根据产品id，分页查询投资信息*/
    List<BidProductInfo> selectBidInfoByProductId(@Param("productId") Integer productId,
                                                  @Param("offset") Integer offset,
                                                  @Param("pageSize") Integer pageSize);

    @Select("""
            select sum(bid_money) as sumBidMoney from b_bid_info;
            """)
    @ResultType(BigDecimal.class)
    /*累计成交金额*/
    BigDecimal selectSumBidMoney();

    int deleteByPrimaryKey(Integer id);

    int insert(BidInfo record);

    int insertSelective(BidInfo record);

    BidInfo selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(BidInfo record);

    int updateByPrimaryKey(BidInfo record);


}